package com.swak.pool;

import java.lang.ref.SoftReference;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.function.Supplier;

/**
 * 池化技术
 * 
 * @author DELL
 */
public interface Pool<T> {

	T borrow();

	void release(T t);

	void clear();

	public static class Builder<T> {
		private Supplier<T> newFunc;

		public Builder<T> New(Supplier<T> newFunc) {
			this.newFunc = newFunc;
			return this;
		}

		public Pool<T> build() {
			return new PoolImpl<T>(newFunc, new SoftReferenceQueue<T>(new ConcurrentLinkedQueue<SoftReference<T>>()));
		}
	}
}